using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the WebControl class.
	/// </summary>
	[Serializable]
	public partial class WebControlCollection : ActiveList<WebControl,WebControlCollection> 
	{	   
		public WebControlCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_WebControl table.
	/// </summary>
	[Serializable]
	public partial class WebControl : ActiveRecord<WebControl>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public WebControl()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public WebControl(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public WebControl(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public WebControl(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_WebControl", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarWebControlID = new TableSchema.TableColumn(schema);
				colvarWebControlID.ColumnName = "WebControlID";
				colvarWebControlID.DataType = DbType.Guid;
				colvarWebControlID.MaxLength = 0;
				colvarWebControlID.AutoIncrement = false;
				colvarWebControlID.IsNullable = false;
				colvarWebControlID.IsPrimaryKey = true;
				colvarWebControlID.IsForeignKey = false;
				colvarWebControlID.IsReadOnly = false;
				colvarWebControlID.DefaultSetting = @"";
				colvarWebControlID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarWebControlID);
				
				TableSchema.TableColumn colvarFullyQualifiedName = new TableSchema.TableColumn(schema);
				colvarFullyQualifiedName.ColumnName = "FullyQualifiedName";
				colvarFullyQualifiedName.DataType = DbType.String;
				colvarFullyQualifiedName.MaxLength = 255;
				colvarFullyQualifiedName.AutoIncrement = false;
				colvarFullyQualifiedName.IsNullable = false;
				colvarFullyQualifiedName.IsPrimaryKey = false;
				colvarFullyQualifiedName.IsForeignKey = false;
				colvarFullyQualifiedName.IsReadOnly = false;
				colvarFullyQualifiedName.DefaultSetting = @"";
				colvarFullyQualifiedName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFullyQualifiedName);
				
				TableSchema.TableColumn colvarMaySpecifyWidth = new TableSchema.TableColumn(schema);
				colvarMaySpecifyWidth.ColumnName = "MaySpecifyWidth";
				colvarMaySpecifyWidth.DataType = DbType.Boolean;
				colvarMaySpecifyWidth.MaxLength = 0;
				colvarMaySpecifyWidth.AutoIncrement = false;
				colvarMaySpecifyWidth.IsNullable = false;
				colvarMaySpecifyWidth.IsPrimaryKey = false;
				colvarMaySpecifyWidth.IsForeignKey = false;
				colvarMaySpecifyWidth.IsReadOnly = false;
				colvarMaySpecifyWidth.DefaultSetting = @"";
				colvarMaySpecifyWidth.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMaySpecifyWidth);
				
				TableSchema.TableColumn colvarMaySpecifyHeight = new TableSchema.TableColumn(schema);
				colvarMaySpecifyHeight.ColumnName = "MaySpecifyHeight";
				colvarMaySpecifyHeight.DataType = DbType.Boolean;
				colvarMaySpecifyHeight.MaxLength = 0;
				colvarMaySpecifyHeight.AutoIncrement = false;
				colvarMaySpecifyHeight.IsNullable = false;
				colvarMaySpecifyHeight.IsPrimaryKey = false;
				colvarMaySpecifyHeight.IsForeignKey = false;
				colvarMaySpecifyHeight.IsReadOnly = false;
				colvarMaySpecifyHeight.DefaultSetting = @"";
				colvarMaySpecifyHeight.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMaySpecifyHeight);
				
				TableSchema.TableColumn colvarDefaultWidth = new TableSchema.TableColumn(schema);
				colvarDefaultWidth.ColumnName = "DefaultWidth";
				colvarDefaultWidth.DataType = DbType.Int16;
				colvarDefaultWidth.MaxLength = 0;
				colvarDefaultWidth.AutoIncrement = false;
				colvarDefaultWidth.IsNullable = true;
				colvarDefaultWidth.IsPrimaryKey = false;
				colvarDefaultWidth.IsForeignKey = false;
				colvarDefaultWidth.IsReadOnly = false;
				colvarDefaultWidth.DefaultSetting = @"";
				colvarDefaultWidth.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDefaultWidth);
				
				TableSchema.TableColumn colvarDefaultHeight = new TableSchema.TableColumn(schema);
				colvarDefaultHeight.ColumnName = "DefaultHeight";
				colvarDefaultHeight.DataType = DbType.Int16;
				colvarDefaultHeight.MaxLength = 0;
				colvarDefaultHeight.AutoIncrement = false;
				colvarDefaultHeight.IsNullable = true;
				colvarDefaultHeight.IsPrimaryKey = false;
				colvarDefaultHeight.IsForeignKey = false;
				colvarDefaultHeight.IsReadOnly = false;
				colvarDefaultHeight.DefaultSetting = @"";
				colvarDefaultHeight.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDefaultHeight);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = false;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				colvarCreatedOn.DefaultSetting = @"";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_WebControl",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("WebControlID")]
		public Guid WebControlID 
		{
			get { return GetColumnValue<Guid>(Columns.WebControlID); }

			set { SetColumnValue(Columns.WebControlID, value); }

		}

		  
		[XmlAttribute("FullyQualifiedName")]
		public string FullyQualifiedName 
		{
			get { return GetColumnValue<string>(Columns.FullyQualifiedName); }

			set { SetColumnValue(Columns.FullyQualifiedName, value); }

		}

		  
		[XmlAttribute("MaySpecifyWidth")]
		public bool MaySpecifyWidth 
		{
			get { return GetColumnValue<bool>(Columns.MaySpecifyWidth); }

			set { SetColumnValue(Columns.MaySpecifyWidth, value); }

		}

		  
		[XmlAttribute("MaySpecifyHeight")]
		public bool MaySpecifyHeight 
		{
			get { return GetColumnValue<bool>(Columns.MaySpecifyHeight); }

			set { SetColumnValue(Columns.MaySpecifyHeight, value); }

		}

		  
		[XmlAttribute("DefaultWidth")]
		public short? DefaultWidth 
		{
			get { return GetColumnValue<short?>(Columns.DefaultWidth); }

			set { SetColumnValue(Columns.DefaultWidth, value); }

		}

		  
		[XmlAttribute("DefaultHeight")]
		public short? DefaultHeight 
		{
			get { return GetColumnValue<short?>(Columns.DefaultHeight); }

			set { SetColumnValue(Columns.DefaultHeight, value); }

		}

		  
		[XmlAttribute("CreatedOn")]
		public DateTime CreatedOn 
		{
			get { return GetColumnValue<DateTime>(Columns.CreatedOn); }

			set { SetColumnValue(Columns.CreatedOn, value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		private Medianamik.SubsonicDALProvider.DAL.PropertyXCollection colPropertyXRecords;
		public Medianamik.SubsonicDALProvider.DAL.PropertyXCollection PropertyXRecords()
		{
			if(colPropertyXRecords == null)
				colPropertyXRecords = new Medianamik.SubsonicDALProvider.DAL.PropertyXCollection().Where(PropertyX.Columns.WebControlId, WebControlID).Load();
			return colPropertyXRecords;
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varWebControlID,string varFullyQualifiedName,bool varMaySpecifyWidth,bool varMaySpecifyHeight,short? varDefaultWidth,short? varDefaultHeight,DateTime varCreatedOn)
		{
			WebControl item = new WebControl();
			
			item.WebControlID = varWebControlID;
			
			item.FullyQualifiedName = varFullyQualifiedName;
			
			item.MaySpecifyWidth = varMaySpecifyWidth;
			
			item.MaySpecifyHeight = varMaySpecifyHeight;
			
			item.DefaultWidth = varDefaultWidth;
			
			item.DefaultHeight = varDefaultHeight;
			
			item.CreatedOn = varCreatedOn;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varWebControlID,string varFullyQualifiedName,bool varMaySpecifyWidth,bool varMaySpecifyHeight,short? varDefaultWidth,short? varDefaultHeight,DateTime varCreatedOn)
		{
			WebControl item = new WebControl();
			
				item.WebControlID = varWebControlID;
			
				item.FullyQualifiedName = varFullyQualifiedName;
			
				item.MaySpecifyWidth = varMaySpecifyWidth;
			
				item.MaySpecifyHeight = varMaySpecifyHeight;
			
				item.DefaultWidth = varDefaultWidth;
			
				item.DefaultHeight = varDefaultHeight;
			
				item.CreatedOn = varCreatedOn;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn WebControlIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn FullyQualifiedNameColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn MaySpecifyWidthColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn MaySpecifyHeightColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn DefaultWidthColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn DefaultHeightColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string WebControlID = @"WebControlID";
			 public static string FullyQualifiedName = @"FullyQualifiedName";
			 public static string MaySpecifyWidth = @"MaySpecifyWidth";
			 public static string MaySpecifyHeight = @"MaySpecifyHeight";
			 public static string DefaultWidth = @"DefaultWidth";
			 public static string DefaultHeight = @"DefaultHeight";
			 public static string CreatedOn = @"CreatedOn";
						
		}

		#endregion
		
		
		
	}

}

